#ifndef __UTILS_H__
#define __UTILS_H__

#include <cstdlib>
#include <iostream>
#include <cmath>
#include "Real.hpp"

using namespace std;

typedef unsigned int Iteration;
typedef unsigned long long BigInt;

// Interpreta los parámetros de entrada del programa
bool parseParams( int argc, char** argv, Iteration &iterations, Iteration& pcount, Iteration& icount, bool& output );

// Potencia definida para reales
double pow( const Real& r, unsigned long y );

// Corre el algoritmo interpretando los argumentos
template<typename T>
int run( T (*algorithm)( Iteration ), Iteration defIter, int argc, char** argv )
{

	bool verbose = false;
	Iteration iterations = defIter, pcount = 0, icount = 0;

	if( parseParams( argc, argv, iterations, pcount, icount, verbose ) )
		return 1;

	cout.precision(100); // imprime con precisión máxima de 100 dígitos

	bool printIteration = icount > iterations;
	unsigned int digits = Real::precision();
	for( Iteration i = iterations ; i <= icount ; i++ )
	{
		for( Iteration c = digits ; c <= pcount ; c++ )
		{
			Real::precision( c );
			if( verbose )
			{
				if( printIteration )
					cout << i << "\t";
				cout << c << "\t";
			}
			cout << algorithm(i) << endl;
		}
	}
	
	return 0;

}

#endif

